package com.snap.vseries.chart;

import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;

import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.renderer.LineChartRenderer;

/**
 * x轴小于25个数据集时 显示value的 折线图
 */
public class ELineChart extends BarLineChartBase<LineData> implements LineDataProvider {

    public ELineChart(Context context) {
        super(context);
    }

    public ELineChart(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ELineChart(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void init() {
        super.init();
        mRenderer = new LineChartRenderer(this, mAnimator, mViewPortHandler) {
            @Override
            protected boolean isDrawingValuesAllowed(ChartInterface chart) {
                return getVisibleXRange() < 25;
            }
        };
    }

    @Override
    public LineData getLineData() {
        return mData;
    }

    @Override
    protected void onDetachedFromWindow() {
        // releases the bitmap in the renderer to avoid oom error
        if (mRenderer != null && mRenderer instanceof LineChartRenderer) {
            ((LineChartRenderer) mRenderer).releaseBitmap();
        }
        super.onDetachedFromWindow();
    }

    public void fitScreenWithoutInvalidate() {
        getViewPortHandler().refresh(new Matrix(), this, false);
    }
}
